Skip to content

Conversation

Arachneee
Copy link

@Arachneee Arachneee commented Apr 5, 2025

I'm using your library well.

It's possible to write like the code below, but there's a bug where responsefields and requestfields are initialized. So I added document parameters.

There will be no problem in the process of introducing the restdocs-api-spec library to restdoc, but if you write it with the restdocs-api-spec library from the beginning, it is very useful to write it as follows.

resultActions
                .andExpect(status().isOk())
                .andDo(document("cart-get",
                                new ResourceSnippetParametersBuilder()
                                        .tag("cart")
                                        .description("Get a cart by id")
                                        .responseSchema(Schema.schema("ResponseCart"))
                                        .pathParameters(
                                                parameterWithName("id").description("the cart id"))
                                        .responseFields(
                                                fieldWithPath("total").description("Total amount of the cart."),
                                                fieldWithPath("products").description("The product line item of the cart."),
                                                subsectionWithPath("products[]._links.product").description("Link to the product."),
                                                fieldWithPath("products[].quantity").description("The quantity of the line item."),
                                                subsectionWithPath("products[].product").description("The product the line item relates to."),
                                                subsectionWithPath("_links").description("Links section."))
                                        .links(
                                                linkWithRel("self").ignored(),
                                                linkWithRel("order").description("Link to order the cart."))
                        )
                );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant